﻿using System;
using System.ComponentModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace G.APITest
{
    public class GloabalData : INotifyPropertyChanged
    {
        private static GloabalData instance;
        /// <summary>
        /// 全局数据实例
        /// </summary>
        public static GloabalData Instance
        {
            get
            {
                return instance;
            }
        }

        public G.SL.Net.APISuite.SampleClient SampleClient { get; private set; }

        public GloabalData()
        {
            instance = this;
            this.SampleClient = new SL.Net.APISuite.SampleClient();
        }
        private void OnPropertyChanged(string name)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
        private G.Service.API.Domain.User.UserInfo userInfo;
        /// <summary>
        /// 登录的用户信息
        /// </summary>
        public G.Service.API.Domain.User.UserInfo UserInfo
        {
            get
            {
                if (userInfo == null)
                {
                    if (System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Contains("UserInfo"))
                        userInfo = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings["UserInfo"] as G.Service.API.Domain.User.UserInfo;
                }
                return userInfo;
            }
            set
            {
                if (userInfo != value)
                {
                    userInfo = value;
                    System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings["UserInfo"] = value;
                    System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Save();
                    this.OnPropertyChanged("UserInfo");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
